package com.example.demo;

import utils.DButil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.Scanner;

public class jdbc3 {
    public static void main(String[] args) {
        Connection connection = null;
        PreparedStatement statement = null;

        try {
            connection = DButil.getConnection();

            String sql = "select user_id, username, password, phone, email, school, points from users where user_id = ?";

            statement = connection.prepareStatement(sql);

            Scanner scanner = new Scanner(System.in);
            int id = scanner.nextInt();

            statement.setInt(1,id);

            ResultSet resultSet = statement.executeQuery();

            while (resultSet.next()) {
                // 获取学生Id
                long user_id = resultSet.getLong(1);
                String username = resultSet.getString(2);
                String password = resultSet.getString(3);
                String phone = resultSet.getString(4);
                String email = resultSet.getString(5);
                String school = resultSet.getString(6);
                long points= resultSet.getLong(7);
                System.out.println(MessageFormat.format("学生编号={0}, 姓名={1}, 密码={2}, 手机号={3}, 邮箱={4}, 学校={5}, 点数={6}", user_id, username, password, phone
                        , email, school, points));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DButil.close(null,statement,connection);
        }

    }
}
